<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<!--数据列表插件结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
	.exportBtn{
		background:#339900;
		padding:3px 5px;
		color:#FFFFFF;
		border:0px;
		border-radius:4px;
		float:right;
		cursor:pointer;
		margin-right:20px;
	}
</style>
</head>

<body>
	<div class="page_header">
	<div class="table_tool">
		<ul class="clearfix">			
			<li class="memberDel btn"><i class="icon-remove"></i> 批量删除</li>
			<li class="line"></li>
			<li class="memberGroup btn">
				<i class="icon-group"></i><a id="ydz">开业停业</a>
				<ul class="submenu">
					<li class="kaiye"  title="批量开业"><i class="icon-caret-right"></i>批量开业</li>
					<li class="tingye" title="批量停业"><i class="icon-caret-right"></i>批量停业</li>
				</ul>
			</li>
			<li class="memberGroup btn">
				<i class="icon-group"></i><a id="ydz">免费配送</a>
				<ul class="peisong submenu">
					<li rel="mianfei"   title="批量开业"><i class="icon-caret-right"></i>开启免费</li>
					<li rel="nomianfei" title="批量停业"><i class="icon-caret-right"></i>关闭免费</li>
				</ul>
			</li>
			<li class="openwin btn" etitle="新增餐厅" eheight="500px" ewidth="1000px" ehref="{:U('Outlet/add')}" id="Outlet_add"><i class="icon-plus"></i> 新增餐厅</li>
			<li class="line"></li>
			<li class="openwin btn" etitle="库存商品管理" eheight="500px" ewidth="900px" ehref="{:U('Product/drink')}" id="Product_drink"><i class="icon-list"></i> 库存商品管理</li>
			<li class="line"></li>
			<li class="openwin btn" etitle="菜品管理" eheight="500px" ewidth="1000px" ehref="{:U('Product/index')}" id="Product_index"><i class="icon-list"></i> 菜品管理</li>
			<li class="btn" id="exportBtn"><i class="icon-share-alt"></i> 导出餐厅</li>
			<!-- <li class="line"></li>
			<li class="openwin btn" etitle="积分礼品管理" eheight="500px" ewidth="900px" ehref="{:U('Integral/index')}" id="Integral_index"><i class="icon-list"></i> 积分礼品管理</li>
			 -->
		</ul>
	</div>
	<form name="searchForm" id="searchForm" method="post" action="{:U('Outlet/export')}">
	<div class="search_box">
	
	<php>if(C('ADMIN_ROLE')==session(C('USER_AUTH_ROLE'))){</php>
		<div >所属地区：<span id="areaBox"></span></div>
	<php>}</php>
		
		
		<!--  星级评分：<select class="form_ele w100" name="level" id="level">
			<option value="">请选择</option>
			<for start="5" end="0.1" step="-0.1" name="k" comparison="gt">
				<option value="{$k}">{$k}</option>
			</for>
		</select>-->
		菜系：
		<select name="cuisine" id="cuisine" class="form_ele w100">
			<option value="">请选择</option>
			<volist name="cuisine" id="v">
				<option value="{$v.id}">{$v.title}</option>
			</volist>
		</select>
		是否停业：
		<select name="is_tingye" id="is_tingye" class="form_ele w100">
			<option value="">请选择</option>
			<option value="1">是</option>
			<option value="0">否</option>
		</select>
		免费配送：
		<select name="is_exempt" id="is_exempt" class="form_ele w100">
			<option value="">请选择</option>
			<option value="1">是</option>
			<option value="2">否</option>
		</select>
		提供发票：
		<select name="is_exempt" id="is_exempt" class="form_ele w100">
			<option value="">请选择</option>
			<option value="1">是</option>
			<option value="2">否</option>
		</select>
		关键字：<input type="text" id="keywords" class="form_ele w100">
		<span id="doSearch" class="doSearch">
			<i class="icon-search"></i> 搜索
		</span>
		<span id="doRest" class="doSearch">重置</span>
	</div>
	</form>
	
	</div>
	<div class="table_box">
	</div>
</body>
<script type="text/javascript">
	var listConfig = {
			gridId : 'memberList',
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			jsonUrl : '__URL__/index',
			where : '',
	 		getWhere : function(){
	 			var where         = {};
				where['type']     = $('#type').val();
				where['level']    = $('#level').val();
				where['cuisine']  = $('#cuisine').val();
				where['keywords'] = $('#keywords').val();
				where['is_tingye']= $('#is_tingye').val();
				where['area2']    = $('.selected2').val();
				where['area3']    = $('.selected3').val();
				where['area4']    = $('.selected4').val();
				where['is_exempt']= $("#is_exempt").val();
				return where;
			},
			
			widthType : 'tdw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : 10,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"addDishes": {
							name: "添加菜品", 
							icon: "add",
							callback: function(key, options) {
								var href   = "{:U('Product/add')}&id="+$(this).attr('rowid');
								var width  = '900px';
								var height = '500px';
								var title  = '添加菜品';
								openDialog('Product_add',href,width,height,title);
							}
						},
						
						"dishes": {
							name: "菜品管理", 
							icon: "add",
							callback: function(key, options) {
								
								var href   = "{:U('Product/index')}&id="+$(this).attr('rowid');
								var width  = '1000px';
								var height = '500px';
								var title  = '菜品管理';
								openDialog('Product_index',href,width,height,title);
							}
						},
						"edit": {
							name: "修改", 
							icon: "edit",
							callback: function(key, options) {
								var href   = "{:U('Outlet/edit')}&id="+$(this).attr('rowid');
								var width  = '1000px';
								var height = '500px';
								var title  = '修改餐厅';
								openDialog('Outlet_edit',href,width,height,title);
							}
						},
						"delete": {
							name: "删除", 
							icon: "edit",
							callback: function(key, options) {
								
								var val = $(this).attr('rowid');
								var msg = "确认要删除该餐厅吗？";
								
								windowApi.lhgdialog.confirm(msg, function(){
									$.post("{:U('Outlet/del')}",{val:val},function(data){
										if(data.status==1){
											$('.et_tfoot .page_refresh').click(); //刷新加载
										}else{
											windowApi.lhgdialog.alert(data.info,function(){return;});
										}
									});
								},function(){
									return;
								});
							}
						}
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : false,
					myclass : 'center',
					edit : false
				},
				{
					display : '名称',
					name : 'title',
					sortable : true,
					myclass : 'center',
					edit : true
				},
				{
					display : '城市',
					name : 'city',
					sortable : true,
					myclass : 'center',
					edit : true
				},
				{
					display : '状态',
					name : 'status',
					sortable : true,
					myclass : 'center',
					edit : true
				},
				{
					display : '免费配送',
					name : 'exempt',
					sortable : true,
					myclass : 'center',
					edit : true,
					width:'80px',
				},
				{
					display : '发票',
					name : 'tigong',
					sortable : true,
					myclass : 'center',
					edit : true,
					width:'40px',
				},
				{
					display : '星级',
					name : 'level',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'50px',
				},
				{
					display : '电话',
					name : 'tel',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '电邮',
					name : 'email',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'100px',
				},
				{
					display : '添加时间',
					name : 'addtime',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'95px'
				},
			]
		};
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	//tableList.erefresh();
	
	//批量开启关闭免费配送
	$(".peisong > li").on('click',function(){
		
		var rel = $(this).attr("rel");
		var val = tableList.getChecked();
		var msg = "确认批量操作选中的餐厅吗？";
		
		if(val&&rel){
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Outlet/distribution')}",{val:val,rel:rel},function(data){
					if(data.status==1){
						$('.et_tfoot .page_refresh').click(); //刷新加载
					}else{
						windowApi.lhgdialog.alert(data.info,function(){return;});
					}
				});
			},function(){return;});
		}else{
			windowApi.lhgdialog.alert('请选择需要操作的餐厅！');
		}
	});
	
	//搜索
 	$('#doSearch').on('click',function(){
		
		var where = tableList.config.getWhere();
		tableList.config.nowPage = 1;
		tableList.config.where   = where;
		tableList.search();
	});
	
 	$("#exportBtn").on('click',function(){
		$("#searchForm").submit();
	})
	
	//重置搜索条件
	$('#doRest').on('click',function(){
		$('#type').val('');
		$('#is_tingye').val('');
		$('#cuisine').val('');
		$('#level').val('');
		$('#keywords').val('');
		$('#is_exempt').val('');
		$('#area2').val('');

		$('.selected2').val('');
		$('.selected3').remove();
		$('.selected4').remove();
	});
 	
 	//批量开业
 	$('.kaiye').on('click',function(){
 		
 		var val  = tableList.getChecked();
 		var type = 0;
		var msg  = "确认要将选中的餐厅设为开业状态吗？";
		
		if(val){
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Outlet/business')}",{val:val,type:type},function(data){
					if(data.status==1){
						$('.et_tfoot .page_refresh').click(); //刷新加载
					}else{
						windowApi.lhgdialog.alert(data.info,function(){return;});
					}
				});
			},function(){
				return;
			});
		}else{
			windowApi.lhgdialog.alert('请选择需要开业的餐厅！');
		}
 	});
 	
 	//批量停业
 	$('.tingye').on('click',function(){
 		
 		var val  = tableList.getChecked();
 		var type = 1;
		var msg  = "确认要将选中的餐厅设为停业状态吗？";
		
		if(val){
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Outlet/business')}",{val:val,type:type},function(data){
					if(data.status==1){
						$('.et_tfoot .page_refresh').click(); //刷新加载
					}else{
						windowApi.lhgdialog.alert(data.info,function(){return;});
					}
				});
			},function(){
				return;
			});
		}else{
			windowApi.lhgdialog.alert('请选择需要停业的餐厅！');
		}
 	});
	
	//批量删除
	$('.memberDel').on('click',function(){
		
		var val = tableList.getChecked();
		var msg = "确认要将选中的餐厅删除吗？";
		
		if(val){
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Outlet/del')}",{val:val},function(data){
					if(data.status==1){
						$('.et_tfoot .page_refresh').click(); //刷新加载
					}else{
						windowApi.lhgdialog.alert(data.info,function(){return;});
					}
				});
			},function(){
				return;
			});
		}else{
			windowApi.lhgdialog.alert('请选择需要删除的餐厅！');
		}
	});
	

	var linkage_json   = {$json|json_encode} ;
	$(function(){
		//初始值处理
		var did = '';
		if(did!=''){
			$('#areaBox').html(dealInitialarea(did,'',1));
		}else{
			$('#areaBox').html(showLinkagearea(39,2,0));
		}
		$('select[name="area"]').live('change',function(){
			var nowLevel  = parseInt($(this).attr('level'));
			var nextLevel = nowLevel+1;
			var enhtml    = '';
			
			//清除自此以后的select
			$('select[name="area"]').each(function(index, element) {
				if(parseInt($(this).attr('level'))>nowLevel){
					$(this).remove();
				}
			});
			
			$('#ssxadd').val($('select[name="area"]').find("option:selected").text());
			
			$('input[name="area'+nowLevel+'"]').val($(this).val());
			//显示下一个select
			//$('#areaBox').append(showLinkagearea($(this).val(),nextLevel,0));
		});
		
		//处理初始值
		function dealInitialarea(lid,result,level){
			if(lid){
				$.each(linkage_json , function(i, n){
					if(lid==i){
						result = dealInitialarea(n[1],result,(parseInt(level)-1))+''+showLinkagearea(n[1],level,i);
						return false;
					}
				});
			}
			return result;
		}
		
		//响应select改变事件
		function showLinkagearea(pid,level,nid){
			var html = ''; //最终输出的HTML
			var have = false; //是否有子词典
			html += '<select name="area" id="area'+level+'" level="'+level+'" class="form_ele w100 selected'+level+'">';
			html += '<option value="0">请选择</option>';
			$.each(linkage_json , function(i, n){
				if(pid==n[1]){
					if(nid==i){
						html += '<option value="'+i+'" selected>'+n[0]+'</option>';
					}else{
						html += '<option value="'+i+'">'+n[0]+'</option>';
					}
					have = true;
				}
			});
			html += '</select>';
			html += '<input type="hidden" name="area'+level+'" id="area'+level+'"/>';
			
			//没有子词典则此次输出为空
			if(!have){
				html = '';
			}
			return html;
		}
	});	
</script>
</html>
